//
//  YKClientVisitManageController.m
//  YunKang
//
//  Created by leoking870 on 2017/9/26.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKClientVisitManageController.h"
#import "YKClientDataItem.h"
#import "YKClientListHeaderView.h"
#import "YKAddClientVisitLogController.h"
#import "YKClientVisitItem.h"
#import "YKClientVisitV2Item.h"
@interface YKClientVisitManageController ()

@end

@implementation YKClientVisitManageController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"客户拜访管理";
    
//    YKClientListHeaderView* headerView = [[YKClientListHeaderView alloc]initWithTitles:@[@"单号",@"客户名称",@"业务员",@"拜访日期"] weights:@[@1,@1,@1,@1]];
//    headerView.backgroundColor = [UIColor tf_colorWithHexString:@"#1EADFC"];
//    [self.view addSubview:headerView];
//    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.top.trailing.equalTo(self.view);
//    }];
    
    UIButton *confirmButton = [[UIButton alloc]init];
    [confirmButton setTitle:@"新增客户拜访" forState:UIControlStateNormal];
    [confirmButton setBackgroundColor:TFSTYLE(buttonEnableBackgroundColor)];
    [confirmButton setTitleColor:TFSTYLE(buttonEnableTitleColor) forState:UIControlStateNormal];
    [self.view addSubview:confirmButton];
    [confirmButton addTarget:self action:@selector(onAddItemTapped:) forControlEvents:UIControlEventTouchUpInside];
    [confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.bottom.trailing.equalTo(self.view);
        make.height.mas_equalTo(40);
    }];
    confirmButton.titleLabel.font = [UIFont systemFontOfSize:14];
    
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.tableFooterView = [UIView new];
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.equalTo(self.view);
//        make.top.equalTo(headerView.mas_bottom);
        make.bottom.equalTo(confirmButton.mas_top);
    }];
    
    self.dataSource.totalPageKey = @"page.totalpage";
    self.dataSource.currentPageKey = @"curpage";
    [self startLoadData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (self.dataSource.manager.sections.count > 0) {
        [self startLoadDataSilently];
    }
}

- (void)onAddItemTapped:(id)sender {
    YKAddClientVisitLogController *vc = [[YKAddClientVisitLogController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (NSDictionary *)pageViewControllerParameters {
    return @{
             kTFPageViewControllerItemClass: [YKClientVisitV2Item class],
             kTFPageViewControllerModelClass:[YKClientVisitModel class],
             kTFPageViewControllerRequestURL:@"customerDataVisitLog/customerDataVisitLogList.htm",
             kTFPageViewControllerDataKeyPath:@"list",
             kTFPageViewControllerRequestParameter:@{@"c_name":[self searchText]}
             };
}
- (void)beginSearchWithText:(NSString *)text {
    [self startLoadData];
}

- (void)customizeItem:(TFTableViewItem *)item {
    //
    item.hideSeparator = NO;
    item.separatorSunk = NO;
    @weakify(self)
    item.selectionHandler = ^(__kindof YKClientVisitItem *item, NSIndexPath *indexPath) {
        YKAddClientVisitLogController *vc = [[YKAddClientVisitLogController alloc]init];
        vc.m_id = item.model.ID;
        [self_weak_.navigationController pushViewController:vc animated:YES];
    };
}

@end
